<!DOCTYPE html>
<html lang="zh-CN">
  <head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
	<#include "/common/plateform/include/common-base.ftl">
  <title>审核流程测试</title>
  <!-- Tell the browser to be responsive to screen width -->
  <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
</head>

<!-- Part 一、 以下是body主体内容的模块区域 -->
<body class="hold-transition ${sysColor} sidebar-mini">
<div class="wrapper">

	<!-- top start -->
	<#include "/common/plateform/top.ftl">
	<!-- top end -->

	<!-- left start -->
	<#include "/common/plateform/left-project.ftl">
	<!-- left end-->

  <div class="content-wrapper">
    <!-- Main start -->
	<section class="content">
      <div class="row">
        <div class="col-xs-12">
			<div class="nav-tabs-custom">
				<ul class="nav nav-tabs" id="myTab-add">
					<li class="active">
						<a href="#tabAdd_1" data-toggle="tab">提交模拟数据</a>
					</li>
					<li>
						<a href="#tabAdd_2" data-toggle="tab">查询待办任务</a>
					</li>
					<li>
						<a href="#tabAdd_3" data-toggle="tab">查询审核历史</a>
					</li>
				</ul>
				<div class="tab-content mytab2">
					<div class="tab-pane active" id="tabAdd_1">
						<div class="box box-solid">
							<div class="box-body">
								<form class="form-horizontal addFormBody" id="tabAdd_1_form" action="javascript:void(0)">
									<input type="hidden" name="pageName" value="sys-audit-flow"/>
									<input type="hidden" name="formName" value="searchForm"/>
									<input type="hidden" name="sysAuditFlow.status" value="1"/>
									<input type="hidden" name="orderBy" value="sysAuditFlow.create_time desc"/>
									<input type="hidden" name="sysAuditFlow.w_sysName" class="input_sysname" value=""/>
								</form>
								<div class="text-danger f12">
									<i class="fa fa-info-circle"></i> 提示：以流程管理所定义数据作为业务数据进行模拟测试各流程操作。
								</div>
									<table class="table table-bordered">
										<thead>
										<tr>
											<th>序号</th>
											<th>流程编号</th>
											<th>流程名称</th>
											<th>创建时间</th>
											<th>操作</th>
										</tr>
										</thead>
										<tbody id="tabAdd_1_form-body">
										</tbody>
									</table>
							</div>
						</div>
					</div>
					<div class="tab-pane" id="tabAdd_2" >
						<div class="box box-solid">
							<div class="box-body">
								<form class="form-horizontal addFormBody" id="tabAdd_2_form" action="javascript:void(0)">
									<input type="hidden" name="pageName" value="sys-audit-search"/>
									<input type="hidden" name="formName" value="searchForm"/>
									<input type="hidden" name="auditType" value="all"/>
									<input type="hidden" name="orderBy" value="sysAudit.create_time desc"/>
									<input type="hidden" name="sysAudit.w_auditsStatus" value="10"/>
									<input type="hidden" name="sysAudit.w_sysName" class="input_sysname" value=""/>
								</form>
								<table class="table table-bordered">
									<thead>
									<tr>
										<th>序号</th>
										<th>流程编号</th>
										<th>任务信息</th>
										<th>业务信息</th>
										<th>创建时间</th>
										<th class="w200">可经办人</th>
										<th>操作</th>
									</tr>
									</thead>
									<tbody id="tabAdd_2_form-body">
									</tbody>
								</table>
							</div>
						</div>
					</div>
					<div class="tab-pane" id="tabAdd_3" >
						<div class="box box-solid">
							<div class="box-body">
								<form class="form-horizontal addFormBody" id="tabAdd_3_form" action="javascript:void(0)">
									<input type="hidden" name="pageName" value="sys-audit-search"/>
									<input type="hidden" name="formName" value="searchForm"/>
									<input type="hidden" name="auditType" value="all"/>
									<input type="hidden" name="orderBy" value="sysAudit.create_time desc"/>
									<input type="hidden" name="sysAudit.wi_auditsStatus" value="90,91"/>
									<input type="hidden" name="sysAudit.w_sysName" class="input_sysname" value=""/>
								</form>
								<table class="table table-bordered">
									<thead>
									<tr>
										<th>序号</th>
										<th>流程编号</th>
										<th>任务信息</th>
										<th>业务信息</th>
										<th>审核信息</th>
										<th>审核时间</th>
									</tr>
									</thead>
									<tbody id="tabAdd_3_form-body">
									</tbody>
								</table>
							</div>
						</div>
					</div>
				</div>
			</div>
           
        </div>
      </div>
  




<!-- Part 二、以下是template模板定义的模块区域 -->
<script type="text/template" id="tabAdd_1_form-template">
		<? for ( var i = 0; i < rows.length; i++) {?>
		<tr>
				<td><?=(i+1)?></td>
				<td><?=strUtil.doNull(rows[i].sysAuditFlow.flowNo,'')?></td>
				<td><?=strUtil.doNull(rows[i].sysAuditFlow.flowName,'')?></td>
				<td><?=strUtil.doNull(rows[i].sysAuditFlow.createTime,'')?></td>
              <td>
				<button type="button" class="btn btn-warning btn-xs" onclick="startFlow('<?=rows[i].sysAuditFlow.flowNo?>','<?=rows[i].sysAuditFlow.flowId?>','测试数据<?=(i+1)?>')"><i class="fa fa-play-circle"></i> 启动流程审核</button>  
			</td>
		</tr>
   <?}?>  		
</script>
<script type="text/template" id="tabAdd_2_form-template">
	<? for ( var i = 0; i < rows.length; i++) {?>
	<tr>
		<td><?=(i+1)?></td>
		<td><?=strUtil.doNull(rows[i].sysAudit.auditType,'')?></td>
		<td>
			<?=strUtil.doNull(rows[i].sysAudit.taskNo,'')?><br/>
			<?=strUtil.doNull(rows[i].sysAudit.taskName,'')?>
		</td>
		<td>
			<?=strUtil.doNull(rows[i].sysAudit.pid,'')?><br/>
			<?=strUtil.doNull(rows[i].sysAudit.proName,'')?><br/>
			<?=strUtil.doNull(rows[i].sysAudit.proId,'')?>
		</td>
		<td><?=strUtil.doNull(rows[i].sysAudit.createTime,'')?></td>
		<td style="word-wrap:break-word;word-break:break-all;"><?=strUtil.doNull(rows[i].sysAudit.checkUser,'')?></td>
		<td>
			<button type="button" class="btn btn-success btn-xs" onclick="doAudit('<?=rows[i].sysAudit.auditsId?>','T')">
				<i class="fa fa-check"></i> 审核通过</button>&nbsp;
			<button type="button" class="btn btn-danger btn-xs" onclick="doAudit('<?=rows[i].sysAudit.auditsId?>','F')">
				<i class="fa fa-close"></i> 审核不通过</button>
		</td>
	</tr>
	<?}?>
</script>
<script type="text/template" id="tabAdd_3_form-template">
	<? for ( var i = 0; i < rows.length; i++) {?>
	<tr>
		<td><?=(i+1)?></td>
		<td><?=strUtil.doNull(rows[i].sysAudit.auditType,'')?></td>
		<td>
			<?=strUtil.doNull(rows[i].sysAudit.taskNo,'')?><br/>
			<?=strUtil.doNull(rows[i].sysAudit.taskName,'')?>
		</td>
		<td>
			<?=strUtil.doNull(rows[i].sysAudit.pid,'')?><br/>
			<?=strUtil.doNull(rows[i].sysAudit.proName,'')?><br/>
			<?=strUtil.doNull(rows[i].sysAudit.proId,'')?>
		</td>
		<td style="word-wrap:break-word;word-break:break-all;">
			审核结果：<?=rows[i].sysAudit.auditsStatus?>-
			<?if('90'==rows[i].sysAudit.auditsStatus){?>审核不通过<?}?>
			<?if('91'==rows[i].sysAudit.auditsStatus){?>审核通过<?}?>
			<br/>
			审核意见：<?=strUtil.doNull(rows[i].sysAudit.auditOpinion,'')?>
		</td>
		<td><?=strUtil.doNull(rows[i].sysAudit.modifyTime,'')?></td>
	</tr>
	<?}?>
</script>
<!-- Part 三、 以下是js模块区域 -->
<script>
var clickMenu = "audit-flow-test";
var myPage,dataListId,searchFormId;
myPage = 10;//定义列表数据
dataListId = "dataList";//显示列表数据div的id
searchFormId = "searchForm";//搜索表单Id
var defSysEname = strUtil.doNull(strUtil.getLocalStorage("sysEname"), "");
$(".input_sysname").val(defSysEname);
/**
 * 初始化数据字典，id传入#id 返回值Map用法：dictListMap["userType"][rows[i].userType]
 */
var dictListMap = DictUtil.initDictAndDymic();
 
$(function () {
	//1、加载分页列表数据
	getTabData('#tabAdd_1');//默认加载第一个tab
	//2、控制是否启用token
	//setToken();
	
 });
$('a[data-toggle="tab"]').on('show.bs.tab', function (e) {
	// 获取已激活的标签页的名称
	var tabId=$(e.target).attr("href");
	console.log('this.click.tabId',tabId);
	getTabData(tabId);
});
 $(function () {
	//设置数据行选中效果
	$('#'+dataListId+' tbody').on('click','tr', function (e) {
	     if ( $(this).hasClass('selected') ) {
	        }
	        else {
	            $('tr.selected').removeClass('selected');
	            $(this).addClass('selected');
	        }
	     //var id = $('tr.selected th').eq(0).html();
	} );
 });

//给模态窗口内form表单内的所有支持必填项的元素注入校验
// $(".modal").on('shown.bs.modal', function () {
// 	$(this).find("form").each(function(){
// 		var formId = $(this).attr("id");
// 		if(!strUtil.isNull(formId)){
// 			formId="#"+formId;
// 		 	setValidate(formId);//定义add表单验证属性
// 			mytools.cleanValidate(formId);//清空上次校验规则提示
// 		}
// 	});
// });

//加载tab列表数据
function getTabData(tabId) {
	var formId = $(tabId).find("form").eq(0).attr("id");
	console.log('tabId='+tabId,"formId="+formId);
	var index_load = layer.load(1, {shade: false});
	$.ajax({
		   type:'get',
		   url:common_list_url,
		   data:$("#"+formId).serialize(),
		   dataType:'json',
		   success: function(myData){
			   layer.close(index_load);
			   console.log('getTabData.res',myData);
			   var data ="";
			   if(myData.total>0){
				   data = baidu.template(formId+"-template",eval(myData));
			   }
				$("#"+formId+"-body").html(data);
			}
		});	
  }

//提交tab1表单数据
function submitForm1(formId,tabId){
	//校验规则-表单提交时触发
	var validate = $('#'+formId).data('bootstrapValidator').validate();
	if(!validate.isValid()){ //如果校验不通过就返回
	    return;  
	}
	
	var index_submit = layer.confirm('您确定要保存信息吗？', {btn: ['Yes','No'],closeBtn: 0,offset: '220px'}
	, function(){
		var result = submitForm(formId,tabId);
		if(result){
			layer.alert("提交成功！", {closeBtn: 0 });
      		mytools.closeModal("my_modal_add");
      		mytools.closeModal("my_modal_edit");
      		refresh();
		
    		
      		setToken();
    		if(!strUtil.isNull(tabId)){
      			$('.nav-tabs a[href=\"#'+tabId+'\"]').tab('show'); // Select tab by name 
      		}
	  	}
	});
	
 }
//提交表单数据
function submitForm(formId,tabId){
	var result;
	var index_load = layer.load(1, {shade: false});
	$.ajax({
	    type:'post',
	    url:common_submit_url,
	    data:$("#"+formId).serialize(),
	    async:false,
	    dataType:'json',
	    success: function(myData){ 
	     console.log(myData);
	        if(myData.flag=="T"){
	        	result = myData;
	    	}else{
	    		setToken();
	     		layer.alert(myData.msg);
	    	}
	        layer.close(index_load);
	  	},
	     error: function (e) {
		     layer.close(index_load);
     	} 
	});	
	return result;
}

//启动流程
function startFlow(auditType,proId,proName){
	var paramData ={
		"pageName":"sys-audit-flow-test","formName":"auditInitForm",
		// "sysAuditFlow.w_flowId":proId,"sysAuditFlow.status":'1',
		"auditType":auditType,
		"pid":proId,
		"proNo":new Date().format("yyyyMMddhhmmss"),
		"proName":proName,
	};
	var tispMsg = "操作确认，本次提交参数：";
	tispMsg+="<br/>流程类型(auditType)："+paramData.auditType;
	tispMsg+="<br/>业务主键(pid)："+paramData.pid;
	tispMsg+="<br/>业务编号(proNo)："+paramData.proNo;
	tispMsg+="<br/>业务标题(proName)："+paramData.proName;
	var index_submit = layer.confirm(tispMsg, {btn: ['继续','取消'],closeBtn: 0,offset: '220px'}
	, function(){
		layer.close(index_submit);
		var index_load = layer.load(1, {shade: false});
		console.log('startFlow.req',paramData);
		$.ajax({
			type: 'post',url: common_submit_url,data:paramData,dataType: 'json',
			success: function (myData) {
				console.log('startFlow.res',myData);
				layer.close(index_load);
				if(myData && myData.flag=='T'){
					layer.msg("启动成功，已初始化第一个节点！");
				}else{
					layer.msg("启动失败！"+myData.msg);
				}
			}
		});
	});
}

//任务审核（通过/不通过）
function doAudit(auditsId,auditFlag){
	var index_load = layer.msg("数据提交中...");
	var paramData ={"pageName":"sys-audit-flow-test","formName":"auditNextForm",
		"auditsId":auditsId,"auditFlag":auditFlag,"auditOpinion":"本任务审核"+(auditFlag=='T'?'可以通过':'不能通过'),
		"result":auditFlag
	};
	console.log('doAudit.req',paramData);
	$.ajax({
		type: 'post',
		url: common_submit_url,
		data:paramData,
		dataType: 'json',
		success: function (myData) {
			console.log('doAudit.res',myData);
			index_load = layer.msg("审核提交完成！");
			getTabData('#tabAdd_2');
		}
	});
}

/**** Part 四、以下是自定义新增方法  ****/
//1.定义校验规则-定义
function setValidate(id){
	$(id).each(function(){
		$(this).bootstrapValidator({
		    feedbackIcons: {
		        valid: 'glyphicon glyphicon-ok',
		        invalid: 'glyphicon glyphicon-remove',
		        validating: 'glyphicon glyphicon-refresh'
		    },/** 以下需要结合实际业务清空补充个表单元素的验证规则 **/
		 	fields:{
		 		/** 可自定义新增验证规则
		    	"uctUser.userEname":{
		    		 validators: {
		    			 regexp: {
		    				 regexp: /^[0-9]+$/,
		                      message: '只能是数字'
		                  }
		              }
		    	}
		    	**/
				}
		});
	});
}


</script>
</section>
<!-- Main end -->   
</div>
	<!-- foot start -->
	<#include "/common/plateform/foot.ftl">
	<!-- foot start -->
</div>
<!-- /.content-wrapper -->
</body>
</html>




















